GRAPHS

Baboon mating

Associating different attributes for the Edges between Nodes

Creating new numerical fields (smaller values) in order to attribute the edge width and/or color

df_graph <- df_graph %>% 
    activate(edges) %>% 
  # computing random number (n) which are between 0 and 1 to attribute the edge width and/or color
    #mutate(edge_weights = runif(n()))
  ## computes numbers between 0 and 1 according to distance in km
  mutate(edge_weights = conceptive)

df_graph
## # A tbl_graph: 224 nodes and 1648 edges
## #
## # An undirected multigraph with 1 component
## #
## # Edge Data: 1,648 x 5 (active)
##    from    to consort conceptive edge_weights
##   <int> <int>   <int>      <int>        <int>
## 1     1   115       1          0            0
## 2     1   115       1          0            0
## 3     1   115       1          0            0
## 4     1   116       1          0            0
## 5     1   116       1          0            0
## 6     1   116       1          0            0
## # ... with 1,642 more rows
## #
## # Node Data: 224 x 3
##   name  centrality group
##   <chr>      <dbl> <int>
## 1 ABB         1.61     6
## 2 ACA       347.       6
## 3 ASH        53.4      6
## # ... with 221 more rows

Layout & Aesthetic Parameters

Choose the types of Edges you would like to display

# igraph layouts

# bipartite <- create_layout(df_graph, layout = 'igraph', algorithm = 'bipartite')
# circle <- create_layout(df_graph, layout = 'igraph', algorithm = 'circle')
# dh <- create_layout(df_graph, layout = 'igraph', algorithm = 'dh')
# drl <- create_layout(df_graph, layout = 'igraph', algorithm = 'drl')
# fr <- create_layout(df_graph, layout = 'igraph', algorithm = 'fr')
# gem <- create_layout(df_graph, layout = 'igraph', algorithm = 'gem')
# graphopt <- create_layout(df_graph, layout = 'igraph', algorithm = 'graphopt')
# grid <- create_layout(df_graph, layout = 'igraph', algorithm = 'grid')
# kk <- create_layout(df_graph, layout = 'igraph', algorithm = 'kk')
# lgl <- create_layout(df_graph, layout = 'igraph', algorithm = 'lgl')
# mds <- create_layout(df_graph, layout = 'igraph', algorithm = 'mds')
# nicely <- create_layout(df_graph, layout = 'igraph', algorithm = 'nicely')
# sphere <- create_layout(df_graph, layout = 'igraph', algorithm = 'sphere')
# star <- create_layout(df_graph, layout = 'igraph', algorithm = 'star')
# sugiyama <- create_layout(df_graph, layout = 'igraph', algorithm = 'sugiyama')

# ggraph layouts

# backbone <- create_layout(df_graph_undirected, layout = 'backbone')

# centrality_bc <- betweenness(df_graph_directed)
# centrality_cc <- closeness(df_graph_directed)
# centrality <- create_layout(df_graph_undirected, layout = 'centrality', centrality = centrality_bc)

# circlepack <- create_layout(df_graph_directed, layout = 'circlepack')
# dendrogram <- create_layout(df_graph_directed, layout = 'dendrogram')
# eigen <- create_layout(df_graph, layout = 'eigen', type = "laplacian", eigenvector = "smallest")

# fabric <- create_layout(cg, layout = 'fabric')
# focus <- create_layout(df_graph_directed, layout = 'focus', focus = 1)

# hive <- create_layout(df_graph, layout = 'hive', axis = friends, sort.by = degree)

# linear <- create_layout(df_graph, layout = 'linear')
# matrix <- create_layout(df_graph, layout = 'matrix')
# partition <- create_layout(df_graph_directed, layout = 'partition')

# pmds_pivots <- 3
# pmds <- create_layout(df_graph, layout = 'pmds', pivots = pmds_pivots)

stress <- create_layout(df_graph, layout = 'stress')
# sunburst <- create_layout(df_graph_directed, layout = 'partition', circular = TRUE)
# treemap <- create_layout(df_graph_directed, layout = 'treemap')

# df_unrooted <- df_graph_undirected %>%  activate(edges) %>%  mutate(length = runif(n()))
# unrooted <- create_layout(df_graph_undirected, layout = 'unrooted' )

Layout & Aesthetic Parameters

Choose the types of Edges you would like to display

# Edge Types
# geom_edge_arc
# geom_edge_arc0
# geom_edge_arc2
# geom_edge_density
# geom_edge_diagonal
# geom_edge_diagonal0
# geom_edge_diagonal2
# geom_edge_elbow
# geom_edge_elbow0
# geom_edge_elbow2
# geom_edge_fan
# geom_edge_fan0
# geom_edge_fan2
# geom_edge_hive
# geom_edge_hive0
# geom_edge_hive2
# geom_edge_link
# geom_edge_link0
# geom_edge_link2
# geom_edge_loop
# geom_edge_loop0

Plot

nicely

theme_opts <- theme(
    text = element_text(family = "inconsolata"), 
    # plot.margin = unit(c(1.5,1,1,1), "in"),
    legend.position='none'
)

v1 <- ggraph(stress) + 
  geom_edge_link(aes(colour = factor(conceptive))) +
  geom_node_point(aes(color = group, size = centrality)) +
  geom_node_text(aes(label = name)) +
  scale_color_gradient(low = "green", high = "blue", na.value = NA) +
  scale_size(range = c(1,6)) +
  theme_graph()+
  theme_opts

girafe(ggobj = v1, width_svg = 1280/72, height_svg = 720/72,
       options = list(opts_sizing(rescale = TRUE, width = 1.0))
)

References

citations for narrative and data sources